<?php session_start();
$host  = $_SERVER['HTTP_HOST'];
if ($_SERVER['SERVER_NAME'] == 'localhost'){$uri="/kalender";}else{$uri="";}
if (!isset($_SESSION['id_user']) || $_SESSION['id_user']=='') {
	echo "<script language=Javascript> location.href='http://$host$uri/index.php'; </script>";	
}else{
	
	if (!is_object($bd)){	
		//me conecto a la base de datos
		require("../globals/Db.class.php");
		require("../globals/Conf.class.php");
		$bd=Db::getInstance();	
	}
	if (!is_object($util)){	
		include("../globals/Util.class.php");		
		$util=Util::getInstance();
	}		
	
	$util->debugOn();
	
	$texto = str_replace("'","&apos;",$_POST["elm1"]);
	$titulo = str_replace("'","&apos;",$_POST["titulo"]);
	$path = $_POST["imagen_path"];
	$code = $util->get_rand_str(10);
	$texto_plano = str_replace("'","&apos;",$_POST["texto_plano"]);
	$tags = $_POST["tags"];
	
	$query="insert into notinews (cuerpo, fecha, titulo, code, path, plano, tags) values ('$texto', now(), '$titulo', '$code', '$path', '$texto_plano', '$tags')";
	$bd->eje($query);
	$funco = (intval($bd->lastId())>0);	
	if ($funco){	
		echo "<script language=Javascript> location.href='http://$host$uri/nuevaNoticia.php?error=0'; </script>";
	}else{
		echo "<script language=Javascript> location.href='http://$host$uri/nuevaNoticia.php?error=1'; </script>";
	}
}
?>